package com.dai.spec.gxk.controller;

import com.dai.spec.common.annotation.Log;
import com.dai.spec.common.core.controller.BaseController;
import com.dai.spec.common.core.domain.AjaxResult;
import com.dai.spec.common.core.page.TableDataInfo;
import com.dai.spec.common.enums.BusinessType;
import com.dai.spec.gxk.domain.CourseSelectionLimit;
import com.dai.spec.gxk.service.SelectionLimitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * 选课数量限制信息管理Controller
 *
 * @author daikl
 * @date
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/gxk/selectionLimit")
@Api("选课数量限制管理")
public class SelectionLimitController extends BaseController {

    private final SelectionLimitService selectionLimitService;

    public SelectionLimitController(SelectionLimitService selectionLimitService) {
        this.selectionLimitService = selectionLimitService;
    }


    /**
     * 查询选课数量限制列表
     */
    @ApiOperation("查询选课数量限制列表")
    @PreAuthorize("@ss.hasPermi('gxk:selectionLimit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseSelectionLimit courseSelectionLimit) {
        if (courseSelectionLimit == null){
            return null;
        }
        startPage();
        List<CourseSelectionLimit> list = selectionLimitService.list();
        if (list == null || list.isEmpty()){
            return new TableDataInfo(Collections.emptyList(),0);
        }
        return getDataTable(list);
    }
    /**
     * 获取选课数量限制详细信息
     */
    @ApiOperation("获取课程详细信息")
    @PreAuthorize("@ss.hasPermi('gxk:selectionLimit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(selectionLimitService.getById(id));
    }
    /**
     * 修改选课数量限制信息
     */
    @ApiOperation("修改选课数量限制")
    @PreAuthorize("@ss.hasPermi('gxk:selectionLimit:edit')")
    @Log(title = "选课数量限制信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseSelectionLimit courseSelectionLimit) {
        return toAjax(selectionLimitService.updateById(courseSelectionLimit));
    }
}
